$(function () {
    var addpage = 2;
    var optionsRadiosInlineVal = ''
    var isInputVal = false;
    var answerObj = [];


    function popFn(dataType, data, dataOption, datathisid, tittxt) {
        popHtml = ''
        popHtml += '<div id="graybg_pop" class="graybg_pop ie6fixed_t" style="display:block"></div>'
        popHtml += '<div class="col-lg-3 teacher_pop goods_pop" style="height:440px;margin-top:-220px;display:block">'
        popHtml += '    <span class="teacher_tit">' + tittxt + '</span>'
        popHtml += '    <i class="fa fa-times" aria-hidden="true"></i>'
        popHtml += '    <form action="" id="form_id">'
        popHtml += '    <div class="form-group">'
        popHtml += '        <label>图片</label>'
        popHtml += '        <div class="big-photo">'

        // popHtml += '            <div id="preview">'
        popHtml += '            <div id="filePicker">'

        // popHtml += '<div id="img">上传图片<input id="inputfile" type="file"  style="position: absolute; width: 100%; height: 100%; left: 0px; top: 0px; opacity: 0; cursor: pointer;"></div>'

        // if(dataType == 1){
        //     popHtml += '<img id="jg" src="'+ data.goods_img +'" data_src = '+ data.goods_img +' class="imgbox" style="display:block"></img>'
        // }else{
        //     popHtml += '<img id="jg" src="images/photo_icon.png" class="imgbox" style="display:none"></img>'
        // }
        popHtml += '            </div>'
        // popHtml += '            <div class="viewThumb">'
        // popHtml += '            </div>'
        popHtml += '        </div>'
        popHtml += '    </div>'

        popHtml += '    <div class="form-group_box clearfix" style="clear:both">'
        if (dataType == 1) {
            popHtml += '    <div class="form-group">'
            popHtml += '        <label>商品名称</label>'
            popHtml += '        <input class="form-control txt_ipt goodsname" value="' + data.name + '" placeholder="请输入商品名称">'
        } else {
            popHtml += '    <div class="form-group col-lg-6 group_left">'
            popHtml += '        <label>商品名称</label>'
            popHtml += '        <input class="form-control txt_ipt goodsname" value="" placeholder="请输入商品名称">'
        }
        popHtml += '    </div>'
        if (dataType == 1) {
            popHtml += '    <div class="form-group col-lg-6 group_right" style="display:none;">'
        } else {
            popHtml += '    <div class="form-group col-lg-6 group_right">'
        }


        popHtml += '        <label>一级分类</label>'
        popHtml += '            <select class="form-control goodsclass">'
        for (var i = 0; i < dataOption.length; i++) {
            popHtml += '               <option data_id = "' + dataOption[i].id + '">' + dataOption[i].name + '</option>'
        }
        popHtml += '            </select>'
        popHtml += '    </div>'
        popHtml += '    </div>'


        popHtml += '    <div class="form-group">'
        popHtml += '        <label>商品描述</label>'
        if (dataType == 1) {
            popHtml += '        <textarea class="form-control text_ipt goodsinfo" rows="3"  placeholder="请输入商品描述">' + data.description + '</textarea>'
        } else {
            popHtml += '        <textarea class="form-control text_ipt goodsinfo" rows="3"  placeholder="请输入商品描述"></textarea>'
        }
        popHtml += '    </div>'

        popHtml += '    <div class="form-group_box clearfix">'
        popHtml += '    <div class="form-group col-lg-6 group_left money">'
        popHtml += '        <label>原价</label>'
        if (dataType == 1) {
            popHtml += '        <input class="form-control txt_ipt ori_proice" value="' + data.original_price + '" placeholder="请输入原价">'
        } else {
            popHtml += '        <input class="form-control txt_ipt ori_proice" value="" placeholder="请输入原价">'
        }
        popHtml += '    </div>'
        popHtml += '    <div class="form-group col-lg-6  group_right money">'
        popHtml += '        <label>现价</label>'
        if (dataType == 1) {
            popHtml += '        <input class="form-control txt_ipt curproice" value="' + data.current_price + '" placeholder="请输入现价">'
        } else {
            popHtml += '        <input class="form-control txt_ipt curproice" value="" placeholder="请输入现价">'
        }
        popHtml += '    </div>'
        popHtml += '    </div>'

        popHtml += '    <div class="form-group_box clearfix">'
        if (dataType == 1) {
            popHtml += '    <div class="form-group col-lg-4 group_left radio" style="display:none">'
        } else {
            popHtml += '    <div class="form-group col-lg-4 group_left radio">'
        }
        popHtml += '          <label>类型</label>'
        popHtml += '          <label class="radio-inline">'
        popHtml += '                <input type="radio" name="optionsRadiosInline" id="optionsRadiosInline1" value="1" checked>教学'
        popHtml += '          </label>'
        popHtml += '          <label class="radio-inline">'
        popHtml += '                <input type="radio" name="optionsRadiosInline" id="optionsRadiosInline2" value="2" >行测'
        popHtml += '          </label>'
        popHtml += '    </div>'


        popHtml += '    <div class="form-group col-lg-4 group_left radio" >'
        popHtml += '          <label>费用</label>'
        popHtml += '          <label class="radio-inline">'
        popHtml += '                <input type="radio" name="optionsRadiosInline2" id="optionsRadiosInline5" value="2" checked>收费'
        popHtml += '          </label>'
        popHtml += '          <label class="radio-inline">'
        popHtml += '                <input type="radio" name="optionsRadiosInline2" id="optionsRadiosInline6" value="1" >免费'
        popHtml += '          </label>'
        popHtml += '    </div>'
        if (dataType == 1) {
            popHtml += '    <div class="form-group col-lg-4 group_right radio" style="display:none">'
        } else {
            popHtml += '    <div class="form-group col-lg-4 group_right radio">'
        }
        popHtml += '          <label>类别</label>'
        popHtml += '          <label class="radio-inline">'
        popHtml += '                <input type="radio" name="optionsRadiosInline1" id="optionsRadiosInline3" value="1" checked>答题'
        popHtml += '          </label>'
        popHtml += '          <label class="radio-inline">'
        popHtml += '                <input type="radio" name="optionsRadiosInline1" id="optionsRadiosInline4" value="2" >视频'
        popHtml += '          </label>'
        popHtml += '    </div>'
        popHtml += '    </div>'
        if (dataType == 1) {
            popHtml += '    <p class="p_btn"  style="padding-top:50px;"><button type="button" class="btn btn-lg btn-success add_ok" data_type="' + dataType + '"  data_id="' + datathisid + '">确定</button></p>'
        } else {
            popHtml += '    <p class="p_btn"><button type="button" class="btn btn-lg btn-success add_ok" data_type="' + dataType + '">确定</button></p>'
        }
        popHtml += '    </form>'
        popHtml += '</div>'
    }

// 四级video模板
    function fourFn(titTxt, type, video) {
        fourHtml = ''
        fourHtml += '<div id="graybg_pop" class="graybg_pop ie6fixed_t" style="display:block"></div>'
        fourHtml += '<div class="col-lg-3 teacher_pop " style="height:330px;margin-top:-150px;display:block">'
        fourHtml += '    <span class="teacher_tit">' + titTxt + '</span>    '
        fourHtml += '    <i class="fa fa-times fourclose" aria-hidden="true"></i>'

        fourHtml += '    <div class="form-group">'
        fourHtml += '        <label>视频名称</label>'
        fourHtml += '        <input class="form-control txt_ipt goodsname" value="' + video.name + '" placeholder="请输入商品名称">'
        fourHtml += '    </div>'

        fourHtml += '    <div class="form-group">'
        fourHtml += '        <label>视频描述</label>'
        fourHtml += '        <input class="form-control txt_ipt goodsinfo" value="' + video.description + '" placeholder="请输入商品名称">'
        fourHtml += '    </div>'

        fourHtml += '    <div class="form-group">'
        // fourHtml += '    <div class="form-group" style="width:50%;float:left;">'
        // fourHtml += '        <label>视频主图</label>'
        // fourHtml += '         <div id="filePicker"></div>'
        // fourHtml += '    </div>'

        fourHtml += '    <div class="form-group" style="width:50%;float:left;">'
        fourHtml += '        <label>视频</label>'
        fourHtml += '         <div id="filePickerVideo"></div>'
        fourHtml += '    </div>'
        fourHtml += '    </div>'

        fourHtml += '    <p class="p_btn">'
        fourHtml += '        <button type="button" class="btn btn-lg btn-success video_btn" data_type="' + type + '" data_id="' + video.id + '">确定</button>'
        fourHtml += '    </p>'
        fourHtml += '</div>'
    }

// 四级txt模板
    function txtFn(titTxt, type, text) {
        fourHtml = ''
        fourHtml += '<div id="graybg_pop" class="graybg_pop ie6fixed_t" style="display:block"></div>'
        fourHtml += '<div class="col-lg-3 teacher_pop " style="display:block;height:440px;margin-top:-220px;">'
        fourHtml += '    <span class="teacher_tit">' + titTxt + '</span>    '
        fourHtml += '    <i class="fa fa-times fourclose" aria-hidden="true"></i>'

        fourHtml += '    <div class="form-group ">'
        fourHtml += '        <label>题目标题</label>'
        fourHtml += '       <div class="form-group_box ">'
        fourHtml += '           <div class="form-control four_txt txt_ipt goodsname" contenteditable="true" style="">' + text.subject + '</div>'
        // fourHtml += '           <input class="form-control four_txt txt_ipt goodsname" value="' + text.subject + '" placeholder="请输入商品名称">'
        fourHtml += '           <div class="txtupload titxtupload" style="" id="imgTit"></div>'
        fourHtml += '       </div>'
        fourHtml += '    </div>'

        fourHtml += '    <div class="form-group">'
        fourHtml += '        <label>题目解析</label>'
        fourHtml += '       <div class="form-group_box ">'
        fourHtml += '           <div class="form-control four_txt content_txt txt_ipt goodsinfo" contenteditable="true" style="">' + text.explain + '</div>'
        // fourHtml += '           <input class="form-control four_txt content_txt txt_ipt goodsinfo" value="' + text.explain + '" placeholder="请输入商品名称">'
        fourHtml += '           <div class="txtupload titxtupload" style=""  id="imgjiexi"></div>'
        fourHtml += '       </div>'
        fourHtml += '    </div>'

        fourHtml += '    <div class="form-group col-lg-5 group_left radio">'
        fourHtml += '          <label>类型</label>'
        fourHtml += '          <label class="radio-inline  typeRadios">'
        if (text.type == "1") {
            fourHtml += '                <input type="radio" name="optionsRadiosInline" id="optionsRadiosInline1" class="optionsRadiosInline" value="1" checked>单选'
        } else {
            fourHtml += '                <input type="radio" name="optionsRadiosInline" id="optionsRadiosInline1" class="optionsRadiosInline" value="1">单选'
        }
        fourHtml += '          </label>'
        fourHtml += '          <label class="radio-inline  typeRadios">'
        if (text.type == "2") {
            fourHtml += '                <input type="radio" name="optionsRadiosInline" id="optionsRadiosInline2" class="optionsRadiosInline" value="2" checked>多选'
        } else {
            fourHtml += '                <input type="radio" name="optionsRadiosInline" id="optionsRadiosInline2" class="optionsRadiosInline" value="2">多选'
        }
        fourHtml += '          </label>'
        fourHtml += '          <label class="radio-inline  typeRadios">'
        if (text.type == "3") {
            fourHtml += '                <input type="radio" name="optionsRadiosInline" id="optionsRadiosInline3" class="optionsRadiosInline" value="3" checked>判断'
        } else {
            fourHtml += '                <input type="radio" name="optionsRadiosInline" id="optionsRadiosInline3" class="optionsRadiosInline" value="3" >判断'
        }
        fourHtml += '          </label>'
        fourHtml += '    </div>'
        fourHtml += '<div class="answer_box">'
        fourHtml += '  <ul class="answer_ul">'
        fourHtml += '  </ul>'
        fourHtml += '  <span class="btn-success answer_btn " style="display:none;">添加选项</span>'
        fourHtml += '</div>'


        fourHtml += '    <p class="p_btn">'
        fourHtml += '        <button type="button" class="btn btn-lg btn-success txt_btn" data_type="' + type + '" data_id="' + text.addId + '">确定</button>'
        fourHtml += '    </p>'
        fourHtml += '</div>'
    }

    function txtHtmlFn(answerTit, liHtmlType, answerPage, value) {
        var liHtml = ''
        liHtml += '    <li class="clearfix">'
        liHtml += '      <span class="answer_tit">' + answerTit + '</span>'
        liHtml += '      <span class="answer_txt">'
        liHtml += '      <div class="daancontent answertxt' + answerPage + '" contenteditable="true" style="">' + value + '</div>'
        // liHtml += '      <input type="text" class="answertxt' + answerPage + '" placeholder="请输入选项" value="' + value + '" 
        liHtml += '      </span>'
        liHtml += '      <label class="radio-inline answerLabel">'
        liHtml += '        ' + liHtmlType + ''
        liHtml += '      </label>'
        liHtml += '      <div class="txtupload litxtupload" id="imgdaan' + answerPage + '" style=""></div>'
        liHtml += '    </li>'
        return liHtml
    }
    
    
    $('body').on('click', '.optionsRadiosInline , .typeRadios', function () {
        if (!admin.isChecked) {
            return
        }
        optionsRadiosInlineVal = $(this).find('.optionsRadiosInline').val()
        $('.answer_ul').html('');
        $('.answer_btn').show();
        admin.answerPage = 0
        admin.answerArr = [];
    })
    $('body').on('click', '.answer_btn', function () {
        var answerTit = ''
        if (admin.answerPage == 0) {
            answerTit = 'A'
            checkedrad = 'checked'
        } else if (admin.answerPage == 1) {
            answerTit = 'B'
            checkedrad = ''
        } else if (admin.answerPage == 2) {
            answerTit = 'C'
            checkedrad = ''
        } else if (admin.answerPage == 3) {
            answerTit = 'D'
            checkedrad = 'chcked'
        }

        var radioHtml = '<input type="radio" name="answerRadio"  class="answerRadio answerRadio' + admin.answerPage + '" value="" ' + checkedrad + '>'
        var checkHtml = '<input type="checkbox" name="answercheck" class="answerRadio answercheck' + admin.answerPage + '" ' + checkedrad + '>'
        if (optionsRadiosInlineVal == 1 || optionsRadiosInlineVal == 3) {
            liHtmlType = radioHtml
        } else if (optionsRadiosInlineVal == 2) {
            liHtmlType = checkHtml
        }

        if (optionsRadiosInlineVal == 1 || optionsRadiosInlineVal == 2) {
            if (admin.answerPage < 4 && $('.answer_ul li').length < 4) {
                $('.answer_ul').append(txtHtmlFn(answerTit, liHtmlType, admin.answerPage, ''))
                admin.answerPage == 3 ? $('.answer_btn').hide() : $('.answer_btn').show()
            } else {
                layer.msg('最多为4个')
            }
        } else if (optionsRadiosInlineVal == 3) {
            if (admin.answerPage < 2 && $('.answer_ul li').length < 2) {
                $('.answer_ul').append(txtHtmlFn(answerTit, liHtmlType, admin.answerPage, ''))
                admin.answerPage == 1 ? $('.answer_btn').hide() : $('.answer_btn').show()
            } else {
                layer.msg('最多为2个')
            }
        }
        
        admin.answerPage++
        var options0 = {
            innerHTML : '上传',
            id : '#imgdaan0',
            uploader : 'uploader0',
            uploadSuccess : function(file, response){
                console.log('成功0')
                $('.answertxt0').append('<img src="'+ response.url +'" class="imgdaan0" width="20" height="20" />')
            }
        }
        var options1 = {
            innerHTML : '上传',
            id : '#imgdaan1',
            uploader : 'uploader1',
            uploadSuccess : function(file, response){
                console.log('成功1')
                $('.answertxt1').append('<img src="'+ response.url +'" class="imgdaan1" width="20" height="20" />')
            }
        }
        var options2 = {
            innerHTML : '上传',
            id : '#imgdaan2',
            uploader : 'uploader2',
            uploadSuccess : function(file, response){
                console.log('成功2')
                $('.answertxt2').append('<img src="'+ response.url +'" class="imgdaan2" width="20" height="20" />')
            }
        }
        var options3 = {
            innerHTML : '上传',
            id : '#imgdaan3',
            uploader : 'uploader3',
            uploadSuccess : function(file, response){
                console.log('成功3')
                $('.answertxt3').append('<img src="'+ response.url +'" class="imgdaan3" width="20" height="20" />')
            }
        }
        if(admin.answerPage == 1){
            admin.uploaderImg(options0)
        }else if(admin.answerPage == 2){
            admin.uploaderImg(options1)
        }else if(admin.answerPage == 3){
            admin.uploaderImg(options2)
        }else if(admin.answerPage == 4){
            admin.uploaderImg(options3)
        }
    })
    
    $('body').on('click', '.txt_btn', function () {
        var dataType = $(this).attr('data_type')
        var dataid = $(this).attr('data_id')
        var dangqianId = $('.add_txt').attr('data_id')
        var LiLength = $('.answer_ul li')
        var cancalData = []
        cancalData.push(dangqianId)
        for (var i = 0; i < LiLength.length; i++) {
            if ($(".answertxt" + i).html().length <= 0) {
                isInputVal = true
            } else {
                isInputVal = false
            }
            admin.answerArr.push({
                question: $(".answertxt" + i).html(),
                answer: $(".answerRadio").get(i).checked ? 1 : 0
            });
        }
        if ($('.goodsname').html().length <= 0) {
            layer.msg('请输入题目名称')
            return false
        } else if ($('.goodsinfo').html().length <= 0) {
            layer.msg('请输入题目解析')
            return false
        } else if ($('.answer_ul').html() == '') {
            layer.msg('请添加选项')
            return false
        } else if (isInputVal) {
            layer.msg('请输入选项')
            return false
        } else {
            // 2添加
            if (dataType == 2) {
                admin.ajaxFn(
                    {
                        url: admin.baseUrl.bankListtAdd,
                        type: 'POST',
                        data: {
                            c_id: dataid,
                            g_id: admin.getCookierl("dangqian"),
                            subject: $('.goodsname').html(),
                            explain: $('.goodsinfo').html(),
                            type: optionsRadiosInlineVal,
                            answer_json: admin.answerArr
                        }
                    },
                    function (data) {
                        admin.ajaxFn(
                            {
                                url: admin.baseUrl.bankList,
                                type: 'POST',
                                data: {
                                    page_size: 100,
                                    page: 1,
                                    category_id: dataid,
                                    g_id: admin.getCookierl("dangqian"),
                                    params: cancalData
                                }
                            },
                            function (data) {
                                $('#graybg_pop , .teacher_pop').remove();
                                layer.msg('添加成功')
                                $('#common').html(template('firstTpl', {'res': data}));
                                admin.answerArr = [];
                            }
                        )

                    }
                )

            } else {
                // 修改
                admin.ajaxFn(
                    {
                        url: admin.baseUrl.bankListUpdate,
                        type: 'POST',
                        data: {
                            // c_id : dataid ,
                            t_id: dataid,
                            g_id: admin.getCookierl("dangqian"),
                            subject: $('.goodsname').html(),
                            explain: $('.goodsinfo').html(),
                            type: $('input:radio[name="optionsRadiosInline"]:checked').val(),
                            answer_json: admin.answerArr
                        }
                    },
                    function (data) {
                        admin.ajaxFn(
                            {
                                url: admin.baseUrl.bankList,
                                type: 'POST',
                                data: {
                                    page_size: 100,
                                    page: 1,
                                    category_id: dangqianId,
                                    g_id: admin.getCookierl("dangqian"),
                                    params: cancalData
                                }
                            },
                            function (data) {
                                $('#graybg_pop , .teacher_pop').remove();
                                layer.msg('修改成功')
                                $('#common').html(template('firstTpl', {'res': data}));
                                admin.answerArr = [];
                            }
                        )

                    }
                )

            }
        }

    })
//添加txt四级
    $('body').on('click', '.add_txt', function () {
        var dataId = $(this).attr('data_id')
        var answerTitF = ''
        txtFn('添加', 2, {
            subject: '',
            explain: '',
            type: '1',
            answer_relation: '',
            addId: dataId
        })
        $('body').append(fourHtml)
        admin.answerArr = [];
        for (var i = 0; i < 4; i++) {
            if (i == 0) {
                answerTitF = 'A'
                checkedrad = 'checked'
            } else if (i == 1) {
                answerTitF = 'B'
                checkedrad = ''
            } else if (i == 2) {
                answerTitF = 'C'
                checkedrad = ''
            } else if (i == 3) {
                answerTitF = 'D'
                checkedrad = ''
            }
            $('.answer_ul').append(txtHtmlFn(answerTitF, '<input type="radio" name="answerRadio" class="answerRadio answerRadio' + admin.answerPage + '" value="" ' + checkedrad + '>', i, ''))
            
        }
        optionsRadiosInlineVal = 1

        var uploadid = ''
        for(var i=0;i<6;i++){
            (function(i){
                if(i==4){
                    uploadid = '#imgTit';
                }else if(i==5){
                    uploadid = '#imgjiexi';
                }else{
                    uploadid='#imgdaan'+i
                }
                admin.uploaderImg({
                    innerHTML : '上传',
                    id : uploadid,
                    uploader : 'uploader'+i,
                    uploadSuccess : function(file, response){
                        console.log('成功'+i)
                        if(i==4){
                            $('.goodsname').append('<img src="'+ response.url +'" class="imgTit" width="20" height="20" />')
                        }else if(i==5){
                            $('.goodsinfo').append('<img src="'+ response.url +'" class="imgjiexi" width="20" height="20" />')
                        }else{
                            $('.answertxt'+i).append('<img src="'+ response.url +'" class="imgdaan0" width="20" height="20" />') 
                        }
                        
                    }
                })
            })(i)
        }


    })
//修改四级txt
    $('body').on('click', '.mod_txt', function () {
        var dataid = $(this).attr('data_id')
        admin.ajaxFn(
            {
                url: admin.baseUrl.bankListMod,
                type: 'POST',
                data: {
                    id: dataid
                }
            },
            function (res) {
                txtFn('修改', 1, {
                    subject: res.subject,
                    explain: res.explain,
                    id: res.id,
                    type: res.type,
                    answer_relation: res.answer_relation,
                    addId: dataid
                })
                $('body').append(fourHtml)
                $(".typeRadios").unbind("click");
                admin.answerArr = [];
                for (var i = 0; i < res.answer_relation.length; i++) {
                    if (i == 0) {
                        answerTitF = 'A'
                    } else if (i == 1) {
                        answerTitF = 'B'
                    } else if (i == 2) {
                        answerTitF = 'C'
                    } else if (i == 3) {
                        answerTitF = 'D'
                    }
                    checkedrad = res.answer_relation[i].answer == 1 ? 'checked' : ''
                    $('.answer_ul').append(txtHtmlFn(
                        answerTitF,
                        res.type == '2' ? '<input type="checkbox" name="answercheck" class="answerRadio answercheck' + i + '" ' + checkedrad + '>' : '<input type="radio" name="answerRadio" class="answerRadio answerRadio' + i + '" value="" ' + checkedrad + '>',
                        i,
                        res.answer_relation[i].question
                    ))

                }
                optionsRadiosInlineVal = res.type
                admin.answerPage = $('.answer_ul li').length
                admin.isChecked = false;
                $('.typeRadios').find('.optionsRadiosInline').attr('disabled', true)
                var uploadid = ''
                for(var i=0;i<6;i++){
                    (function(i){
                        if(i==4){
                            uploadid = '#imgTit';
                        }else if(i==5){
                            uploadid = '#imgjiexi';
                        }else{
                            uploadid='#imgdaan'+i
                        }
                        admin.uploaderImg({
                            innerHTML : '上传',
                            id : uploadid,
                            uploader : 'uploader'+i,
                            uploadSuccess : function(file, response){
                                console.log('成功'+i)
                                if(i==4){
                                    $('.goodsname').append('<img src="'+ response.url +'" class="imgTit" width="20" height="20" />')
                                }else if(i==5){
                                    $('.goodsinfo').append('<img src="'+ response.url +'" class="imgjiexi" width="20" height="20" />')
                                }else{
                                    $('.answertxt'+i).append('<img src="'+ response.url +'" class="imgdaan0" width="20" height="20" />') 
                                }
                                
                            }
                        })
                    })(i)
                }
                var aaa =[0,1,2,3,4,5]
                aaa.map((v , i)=>{
                    if(i==4){
                        uploadid = '#imgTit';
                    }else if(i==5){
                        uploadid = '#imgjiexi';
                    }else{
                        uploadid='#imgdaan'+i
                    }
                    admin.uploaderImg({
                        innerHTML : '上传',
                        id : uploadid,
                        uploader : 'uploader'+i,
                        uploadSuccess : function(file, response){
                            console.log('成功'+i)
                            if(i==4){
                                $('.goodsname').append('<img src="'+ response.url +'" class="imgTit" width="20" height="20" />')
                            }else if(i==5){
                                $('.goodsinfo').append('<img src="'+ response.url +'" class="imgjiexi" width="20" height="20" />')
                            }else{
                                $('.answertxt'+i).append('<img src="'+ response.url +'" class="imgdaan0" width="20" height="20" />') 
                            }
                            
                        }
                    })
                })

            }
        )

    })

    $('body').on('click', '.del_four', function () {
        var datathisid = $(this).attr('data_id')
        var dataaddtxtid = $('.add_txt').attr('data_id')
        var cancalData = []
        cancalData.push(dataaddtxtid)
        layer.open({
            type: 1
            , title: false //不显示标题栏
            , closeBtn: false
            , area: '300px;'
            , shade: 0.8
            , id: 'LAY_layuipro' //设定一个id，防止重复弹出
            , btn: ['确定', '取消']
            , btnAlign: 'c'
            , moveType: 1 //拖拽模式，0或者1
            , content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">确定要删除吗？</div>'
            , yes: function () {
                $('.layui-layer-shade, .layui-layer').remove();
                admin.ajaxFn(
                    {
                        url: admin.baseUrl.bankListRemove,
                        type: 'POST',
                        async: false,
                        data: {
                            id: datathisid
                        }
                    },
                    function (data) {
                        layer.msg('删除成功！')
                        admin.ajaxFn(
                            {
                                url: admin.baseUrl.bankList,
                                type: 'POST',
                                data: {
                                    page_size: 20,
                                    page: 1,
                                    category_id: dataaddtxtid,
                                    g_id: admin.getCookierl("dangqian"),
                                    params: cancalData
                                }
                            },
                            function (data) {
                                $('#graybg_pop , .teacher_pop').remove();
                                $('#common').html(template('firstTpl', {'res': data}));
                            }
                        )
                    }
                )
            }

        });
    })


    admin.ajaxFn(
        {
            url: admin.baseUrl.commonList,
            type: 'GET',
            data: {
                page_size: 100,
                page: 1
            }
        },
        function (data) {
            $('#common').html(template('commonTpl', {'res': data}));
        }
    )


    //添加一级
    $('body').on('click', '.add_list', function () {
        admin.ajaxFn(
            {
                url: admin.baseUrl.commonclassifytList,
                type: 'GET',
                data: {}
            },
            function (data) {
                popFn(2, '', data, '', '添加');
                $('body').append(popHtml)

                admin.webuploaderFn('点击上传', admin.baseUrl.commonListAdd, 'Images', 'gif,jpg,jpeg,png', 'image/gif,image/jpg,image/jpeg,image/png')

            }
        )


    })
    //添加video四级
    $('body').on('click', '.add_video', function () {
        fourFn('添加', 2, {
            name: '',
            description: '',
            img_url: 'images/disimg.png',
            play_url: '',
            id: ''
        })
        $('body').append(fourHtml)
        admin.webuploaderVideoFn('视频上传', admin.baseUrl.videoListtAdd, 'videoImages', 'mp4,flv,jpeg,bmp,doc,docx,rar,pdf', 'video/*,audio/*,application/*')
        // admin.webuploaderFn('视频主图上传' , admin.baseUrl.videoListtAdd ,'Images' , 'gif,jpg,jpeg,png' , 'image/gif,image/jpg,image/jpeg,image/png')    

    })
    //查看
    $('body').on('click', '.info_list', function () {
        var dataid = $(this).attr('data_id')
        admin.ajaxFn(
            {
                url: admin.baseUrl.classifyList,
                type: 'POST',
                data: {
                    id: dataid
                }
            },
            function (data) {
                $('#classnav').html(template('classnavTpl', {'res': data}));
                if (data.data.length == 0) {
                    setTimeout(function () {
                        popFn(1, '');
                        $('body').append(popHtml)
                    }, 500)

                }

            }
        )
    })

    //创建一级
    $('body').on('click', '.create_list', function () {
        datavideoid = $(this).attr('data_id')
        var datatype = $(this).attr('data_type')
        var dataassort = $(this).attr('data_assort')
        datacategory = $(this).attr('data_category')
        admin.setCookierl("typeapplic", datatype, 1, "/");
        admin.setCookierl("assort", dataassort, 1, "/");
        admin.setCookierl("dangqian", datavideoid, 1, "/");
        admin.setCookierl("datacategory_first", datacategory, 1, "/");
        if (dataassort == '答题') {
            dataUrl = datatype == '教学' ? admin.baseUrl.classifyList : admin.baseUrl.classifyLineList
            dataObject = {
                id: datacategory
            }

        } else {
            // 视频直接跳视频列表
            dataUrl = admin.baseUrl.videoList
            dataObject = {
                page_size: 100,
                page: 1,
                category_id: datacategory,
                g_id: datavideoid
            }
        }
        admin.ajaxFn(
            {
                url: dataUrl,
                type: 'POST',
                data: dataObject
            },
            function (data) {
                if (dataassort == '答题') {
                    $('#common').html(template('commoncreateTpl', {'res': data}));
                } else {
                    $('#common').html(template('videoTpl', {'res': data}));
                }

                addpage++

            }
        )
    })

    //二三级详情
    $('body').on('click', '.info_second', function () {
        var dataid = $(this).attr('data_id')
        var datapid = $(this).attr('data_pid')
        var datalevel = $(this).attr('data_level')
        var assort = decodeURIComponent(admin.getCookierl("assort"));
        var type = decodeURIComponent(admin.getCookierl("typeapplic"));
        var cancalData = []
        cancalData.push(dataid)
        if (addpage == 4) {
            dataUrl = admin.baseUrl.bankList
            data = {
                page_size: 100,
                page: 1,
                category_id: dataid,
                g_id: admin.getCookierl("dangqian"),
                params: cancalData
            }
        } else {
            admin.setCookierl("datacategory_second", dataid, 1, "/");
            dataUrl = type == '教学' ? admin.baseUrl.classifyList : admin.baseUrl.classifyLineList
            data = {
                id: dataid,
                params: cancalData
            }
        }
        admin.ajaxFn(
            {
                url: dataUrl,
                type: 'POST',
                data: data
            },
            function (res) {
                if (addpage == 4) {

                    $('#common').html(template('firstTpl', {'res': res}));
                } else {
                    $('#common').html(template('commoncreateTpl', {'res': res}));
                }
                addpage++

            }
        )

    })

    //返回上一级
    $('body').on('click', '.cancal_list', function () {
        var dataid = $(this).attr('data_id')
        var type = decodeURIComponent(admin.getCookierl("typeapplic"));
        var adminUrl = ''
        var ajaxtype = ''
        if (addpage == 3) {
            adminUrl = admin.baseUrl.commonList
            DivTpl = 'commonTpl'
            dataid = admin.getCookierl("datacategory_first")
            ajaxtype = 'GET'
        } else if (addpage == 4 || addpage == 5) {
            dataid = addpage == 5 ? admin.getCookierl("datacategory_second") : dataid
            adminUrl = type == '教学' ? admin.baseUrl.classifyList : admin.baseUrl.classifyLineList
            DivTpl = 'commoncreateTpl'
            ajaxtype = 'POST'
        }
        admin.ajaxFn(
            {
                url: adminUrl,
                type: ajaxtype,
                data: {
                    id: dataid
                }
            },
            function (data) {
                $('#common').html(template(DivTpl, {'res': data}));
            }
        )
        addpage--
    })

    //修改一级
    $('body').on('click', '.mod_list', function () {
        var dataid = $(this).attr('data_id')
        admin.ajaxFn(
            {
                url: admin.baseUrl.commonListMod,
                type: 'post',
                data: {
                    id: dataid
                }
            },
            function (data) {
                var datamod = data
                admin.ajaxFn(
                    {
                        url: admin.baseUrl.commonclassifytList,
                        type: 'GET',
                        data: {}
                    },
                    function (data) {
                        popFn(1, datamod, data, dataid, "修改");
                        $('body').append(popHtml)
                        admin.webuploaderFn('点击修改', admin.baseUrl.commonListUpdate, 'Images', 'gif,jpg,jpeg,png', 'image/gif,image/jpg,image/jpeg,image/png')
                    }
                )


            }
        )

    })
    //修改四级video
    $('body').on('click', '.mod_video', function () {
        var dataid = $(this).attr('data_id')
        admin.ajaxFn(
            {
                url: admin.baseUrl.videoListMod,
                type: 'POST',
                data: {
                    id: dataid
                }
            },
            function (res) {
                fourFn('修改', 1, {
                    name: res.name,
                    description: res.description,
                    img_url: res.img_url == '' ? 'images/disimg.png' : res.img_url,
                    play_url: res.play_url,
                    id: dataid
                })
                $('body').prepend(fourHtml)
                admin.webuploaderVideoFn('视频上传', admin.baseUrl.videoListUpdate, 'videoImages', 'mp4,flv,jpeg,bmp,doc,docx,rar,pdf', 'video/*,audio/*,application/*')
                // var videoBox = new DPlayer({
                //     container:document.getElementById('img_box_video'),
                //     live : false,
                //     video: {
                //         //loop: true, // 是否循环播放
                //         //pic: "", // 视频封面
                //         mutex: true, //互斥，阻止多个播放器同时播放
                //         url: $('#img_box_video').attr('data_src'), // 播放url
                //         type: 'customFlv'
                //         // quality: options.quality, // 清晰度选择
                //         // defaultQuality: 2, // 默认清晰度
                //     }
                // });


            }
        )

    })
    //添加修改四级提交
    $('body').on('click', '.video_btn', function () {
        var dataId = $('.add_list').attr('data_id'),
            datatype = $(this).attr('data_type'),
            datathisid = $(this).attr('data_id')

        if ($('.goodsname').val().length <= 0) {
            layer.msg('请输入视频名称')
            return false
        } else if ($('.goodsinfo').val().length <= 0) {
            layer.msg('请输入视频描述')
            return false
        }
            // else if(admin.isloader) {
            //   layer.msg('请选择视频图片')
            //   return false
        // }
        else if (admin.isloaderVideo) {
            layer.msg('请选择视频')
            return false
        } else {
            // 2添加
            if (datatype == 2) {
                // 添加视频
                admin.uploaderVideo.options.formData.token = admin.getCookierl('cookval');
                admin.uploaderVideo.options.formData.g_id = datavideoid;
                admin.uploaderVideo.options.formData.v_name = $.trim($('.goodsname').val());
                admin.uploaderVideo.options.formData.description = $.trim($('.goodsinfo').val());
                admin.uploaderVideo.options.formData.video = uploaderfile;
                // admin.uploaderVideo.options.formData.img = uploaderfile;
                admin.uploaderVideo.on('uploadSuccess', function (file, response) {
                    admin.ajaxFn(
                        {
                            url: admin.baseUrl.videoList,
                            type: 'POST',
                            data: {
                                page_size: 100,
                                page: 1,
                                category_id: datacategory,
                                g_id: datavideoid
                            }
                        },
                        function (data) {
                            $('#graybg_pop , .teacher_pop').remove();
                            admin.isloader = true;
                            layer.msg('添加成功')
                            $('#common').html(template('videoTpl', {'res': data}));
                        }
                    )
                });
                admin.uploaderVideo.on('uploadComplete', function (file) {

                });
                if (admin.uploaderVideo.state === 'ready') {
                    admin.uploaderVideo.upload();
                } else if (admin.uploaderVideo.state === 'paused') {
                    admin.uploaderVideo.upload();
                } else if (admin.uploaderVideo.state === 'uploading') {
                    admin.uploaderVideo.stop();
                }


            } else {

                // 修改视频
                admin.uploaderVideo.options.formData.token = admin.getCookierl('cookval');
                admin.uploaderVideo.options.formData.v_id = datathisid;
                admin.uploaderVideo.options.formData.v_name = $.trim($('.goodsname').val());
                admin.uploaderVideo.options.formData.description = $.trim($('.goodsinfo').val());
                admin.uploaderVideo.options.formData.video = uploaderfile;
                // admin.uploaderVideo.options.formData.img = uploaderfile;
                admin.uploaderVideo.on('uploadSuccess', function (file, response) {
                    admin.ajaxFn(
                        {
                            url: admin.baseUrl.videoList,
                            type: 'POST',
                            data: {
                                page_size: 100,
                                page: 1,
                                category_id: datacategory,
                                g_id: datavideoid
                            }
                        },
                        function (data) {
                            $('#graybg_pop , .teacher_pop').remove();
                            admin.isloader = true;
                            layer.msg('修改成功')
                            $('#common').html(template('videoTpl', {'res': data}));
                        }
                    )
                });
                admin.uploaderVideo.on('uploadComplete', function (file) {
                });
                if (admin.uploaderVideo.state === 'ready') {
                    admin.uploaderVideo.upload();
                } else if (admin.uploaderVideo.state === 'paused') {
                    admin.uploaderVideo.upload();
                } else if (admin.uploaderVideo.state === 'uploading') {
                    admin.uploaderVideo.stop();
                }

            }


        }

    })
    //删除视频  
    $('body').on('click', '.del_video', function () {
        var datathisid = $(this).attr('data_id')
        layer.open({
            type: 1
            , title: false //不显示标题栏
            , closeBtn: false
            , area: '300px;'
            , shade: 0.8
            , id: 'LAY_layuipro' //设定一个id，防止重复弹出
            , btn: ['确定', '取消']
            , btnAlign: 'c'
            , moveType: 1 //拖拽模式，0或者1
            , content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">确定要删除吗？</div>'
            , yes: function () {
                $('.layui-layer-shade, .layui-layer').remove();
                admin.ajaxFn(
                    {
                        url: admin.baseUrl.videoListRemove,
                        type: 'POST',
                        async: false,
                        data: {
                            id: datathisid
                        }
                    },
                    function (data) {
                        layer.msg('删除成功！')
                        admin.ajaxFn(
                            {
                                url: admin.baseUrl.videoList,
                                type: 'POST',
                                async: false,
                                data: {
                                    page_size: 100,
                                    page: 1,
                                    category_id: datacategory,
                                    g_id: datavideoid
                                }
                            },
                            function (data) {
                                $('#common').html(template('videoTpl', {'res': data}));
                            }
                        )
                    }
                )
            }

        });
    })


    //查看
    $('body').on('click', '.frame_list', function () {
        var dataid = $(this).attr('data_id'),
            datatype = $(this).attr('data_type')
        admin.ajaxFn(
            {
                url: admin.baseUrl.commonListType,
                type: 'POST',
                data: {
                    id: dataid,
                    status: datatype
                }
            },
            function (data) {
                admin.ajaxFn(
                    {
                        url: admin.baseUrl.commonList,
                        type: 'GET',
                        data: {
                            page_size: 100,
                            page: 1
                        }
                    },
                    function (data) {
                        $('#graybg_pop , .teacher_pop').remove();
                        layer.msg('修改成功')
                        $('#common').html(template('commonTpl', {'res': data}));
                    }
                )
            }
        )
    })


    $('body').on('click', 'fourclose', function () {
        $('#graybg_pop , .teacher_pop').remove();
        answerPage = 0

    })


    $('body').on('click', "input[name='optionsRadiosInline2']", function () {
        var feitype = $(this).val();
        if (feitype == 1) {
            $('.ori_proice').val('0').attr({'disabled': 'disabled'})
            $('.curproice').val('0').attr({'disabled': 'disabled'})
        } else {
            $('.ori_proice').val('').prop({'disabled': ''})
            $('.curproice').val('').prop({'disabled': ''})
        }

    })
    //确定
    $('body').on('click', '.add_ok', function () {
      
        var dataId = $('.add_list').attr('data_id'),
            datatype = $(this).attr('data_type'),
            datathisid = $(this).attr('data_id'),
            oriVal = $('.ori_proice').val(), //原价
            curVal = $('.curproice').val() //现价
        var disabledIs = $('.ori_proice').attr('disabled') == 'disabled' ? false : true
        if (admin.isloader) {
            layer.msg('请选择图片')
            return false
        } else if ($('.goodsname').val().length <= 0) {
            layer.msg('请输入商品名称')
            return false
        } else if ($('.goodsname').val().length > 50) {
            layer.msg('商品名称最多为五十个字符')
            return false
        } else if ($('.goodsinfo').val().length <= 0) {
            layer.msg('请输入商品描述')
            return false
        } else if ($('.goodsinfo').val().length > 500) {
            layer.msg('商品描述最多为三百个字符')
            return false
        } else if (isNaN(curVal) || isNaN(oriVal)) {
            layer.msg('原价或现价请输入数字')
            return false
        } else if (oriVal.length <= 0) {
            layer.msg('请输入原价')
            return false
        } else if ((parseInt(oriVal) > 0 && parseInt(oriVal) < 100) || parseInt(oriVal) > 10000) {
            layer.msg('原价不能小于100或不能大于10000')
            return false
        } else if (curVal.length <= 0) {
            layer.msg('请输入现价')
            return false
        } else if ((parseInt(curVal) > 0 && parseInt(curVal) < 100) || parseInt(curVal) > 10000) {
            layer.msg('现价不能小于100或不能大于10000')
            return false
        } else if (parseInt(curVal) >= parseInt(oriVal) && parseInt(curVal) > 0 && parseInt(oriVal) > 0) {
            layer.msg('现价不能大于或等于原价')
            return false
        }else{
            if (datatype == 2) {
                // console.log(uploaderfile)
                admin.uploader.options.formData.token = admin.getCookierl('cookval');
                admin.uploader.options.formData.c_id = $('.goodsclass option:selected').attr('data_id');
                admin.uploader.options.formData.goods_name = $.trim($('.goodsname').val());
                admin.uploader.options.formData.description = $.trim($('.goodsinfo').val());
                // admin.uploader.options.formData.img = uploaderfile;
                admin.uploader.options.formData.original_price = oriVal
                admin.uploader.options.formData.current_price = curVal
                admin.uploader.options.formData.goods_type = $("input[name='optionsRadiosInline']:checked").val()
                admin.uploader.options.formData.assort = $("input[name='optionsRadiosInline1']:checked").val()
                admin.uploader.options.formData.shop_type = $("input[name='optionsRadiosInline2']:checked").val()
                admin.uploader.on('uploadSuccess', function (file, response) {
                    admin.ajaxFn(
                        {
                            url: admin.baseUrl.commonList,
                            type: 'GET',
                            data: {
                                page_size: 100,
                                page: 1
                            }
                        },
                        function (data) {
                            $('#graybg_pop , .teacher_pop').remove();
                            admin.isloader = true;
                            layer.msg('添加成功')
                            $('#common').html(template('commonTpl', {'res': data}));
                        }
                    )
                });
                admin.uploader.on('uploadComplete', function (file) {
                });
                if (admin.uploader.state === 'ready') {
                    admin.uploader.upload();
                } else if (admin.uploader.state === 'paused') {
                    admin.uploader.upload();
                } else if (admin.uploader.state === 'uploading') {
                    admin.uploader.stop();
                }
            } else {
                admin.uploader.options.formData.token = admin.getCookierl('cookval');
                admin.uploader.options.formData.g_id = datathisid;
                admin.uploader.options.formData.goods_name = $.trim($('.goodsname').val());
                admin.uploader.options.formData.description = $.trim($('.goodsinfo').val());
                // admin.uploader.options.formData.img = uploaderfile;
                admin.uploader.options.formData.original_price = oriVal
                admin.uploader.options.formData.current_price = curVal
                admin.uploader.options.formData.shop_type = $("input[name='optionsRadiosInline2']:checked").val()
                admin.uploader.on('uploadSuccess', function (file, response) {
                    admin.ajaxFn(
                        {
                            url: admin.baseUrl.commonList,
                            type: 'GET',
                            data: {
                                page_size: 100,
                                page: 1
                            }
                        },
                        function (data) {
                            $('#graybg_pop , .teacher_pop').remove();
                            admin.isloader = true;
                            layer.msg('修改成功')
                            $('#common').html(template('commonTpl', {'res': data}));
                        }
                    )
                });

                admin.uploader.on('uploadComplete', function (file) {

                });
                
                if (admin.uploader.state === 'ready') {
                    admin.uploader.upload();
                } else if (admin.uploader.state === 'paused') {
                    admin.uploader.upload();
                } else if (admin.uploader.state === 'uploading') {
                    admin.uploader.stop();
                }

            }

        }

    })







})







